﻿using System.Collections.Generic;
using System.Data;
using DevExpress.XtraEditors;
using VASJ.Model.Helper;

namespace VASJ.Helper
{
    public static class DropDownHelper
    {
        public static void SetupList(this LookUpEdit cbx, Dictionary<int, string> dict, int editValue, int popupWidth, bool hasDefaultValue, string defaultValue)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add(ComboBoxHelper.ValueMember);
            dt.Columns.Add(ComboBoxHelper.DisplayMember);

            DataRow dr = dt.NewRow();

            if (hasDefaultValue)
            {
                dr[ComboBoxHelper.ValueMember] = 0;
                dr[ComboBoxHelper.DisplayMember] = defaultValue;
                dt.Rows.Add(dr);
            }

            if (dict != null)
            {
                foreach (KeyValuePair<int, string> kvp in dict)
                {
                    dr = dt.NewRow();
                    dr[ComboBoxHelper.ValueMember] = kvp.Key;
                    dr[ComboBoxHelper.DisplayMember] = kvp.Value;
                    dt.Rows.Add(dr);
                }
            }

            cbx.Properties.DataSource = null;
            cbx.Properties.DataSource = dt;
            cbx.Properties.PopulateColumns();

            for (int i = 0; i < cbx.Properties.Columns.Count; i++)
            {
                cbx.Properties.Columns[i].Visible = false;
            }

            cbx.Properties.Columns[ComboBoxHelper.DisplayMember].Visible = true;

            cbx.EditValue = editValue;

            cbx.Properties.PopupWidth = popupWidth;
        }

        public static void SetupList<T>(this LookUpEdit cbx, T list, int editValue, int popupWidth)
        {

        }
    }
}
